package com.huaxin.device.dto.enums.validator;

import com.huaxin.device.dto.enums.ProtectionLevel;
import com.huaxin.device.dto.enums.validation.ValidProtectionLevel;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class ProtectionLevelValidator implements ConstraintValidator<ValidProtectionLevel, String> {
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        // 允许 null 或空字符串通过（配合 @NotNull/@NotBlank 使用）
        if (value == null || value.trim().isEmpty()) {
            return true;
        }
        return ProtectionLevel.isValid(value);
    }
}